package demo2;

class Height implements Cloneable{
    public int height = 175;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

public class Person implements Cloneable{
    public String name;
    public int age;
    public double score;

    public Person(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    public Height H = new Height();

    //深拷贝
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person)super.clone();
        tmp.H = (Height) this.H.clone();
        return tmp;
    }


    //浅拷贝
//       @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }
}
